﻿using System;
using System.Web.Security;
using System.Web.UI;
using Sfd.Services;

namespace Sfd.WebApp.Projects
{
    public partial class Lists : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                BindDatas();
        }

        private void BindDatas()
        {
            var user = Membership.GetUser();
            if (user == null) return;

            var userId = (Guid) user.ProviderUserKey;
            var projectsService = new ProjectService(true);

            gv.DataSource = User.IsInRole("admin") ? projectsService.LoadAll() : projectsService.GetUserProjects(userId);

            gv.DataBind();
        }
    }
}